<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<SCRIPT>
var paramname = location.search.substr(1);
var hexstr = "#000";
function getcolor(event) {
	var hex = [0,1,2,3,4,5,6,7,8,9,'A','B','C','D','E','F'];
	if(event.clientX > 164 || event.clientY > 164) {
		return;
	}
	var hsv = new Object();
	var h = 164;
	var y = event.clientY;
	hsv.h = 360 * event.clientX / 164;
	if (y > h/2) {
		hsv.s = 1.0;
		hsv.v = 2 * (h - y) / h;
	}
	else {
		hsv.v = 1.0;
		hsv.s = y / (h/2);
	}
	var rgb = hsvToRgb(hsv);
	var red   = Math.round(255 * rgb.r);
	var green = Math.round(255 * rgb.g);
	var blue  = Math.round(255 * rgb.b);
	hexstr = '#' + hex[(red - (red % 16)) / 16].toString() + hex[red % 16].toString()
		 + hex[(green - (green % 16)) / 16].toString() + hex[green % 16].toString()
		 + hex[(blue - (blue % 16)) / 16].toString() + hex[blue % 16].toString()
}

function hsvToRgb(hsv) {
	var rgb = new Object();
	var i, f, p, q, t;

	if(hsv.s == 0) {
		// achromatic (grey)
		rgb.r = rgb.g = rgb.b = hsv.v;
		return rgb;
	}
	hsv.h /= 60;
	i = Math.floor( hsv.h );
	f = hsv.h - i;
	p = hsv.v * ( 1 - hsv.s );
	q = hsv.v * ( 1 - hsv.s * f );
	t = hsv.v * ( 1 - hsv.s * ( 1 - f ) );
	switch( i ) {
		case 0:
			rgb.r = hsv.v;
			rgb.g = t;
			rgb.b = p;
			break;
		case 1:
			rgb.r = q;
			rgb.g = hsv.v;
			rgb.b = p;
			break;
		case 2:
			rgb.r = p;
			rgb.g = hsv.v;
			rgb.b = t;
			break;
		case 3:
			rgb.r = p;
			rgb.g = q;
			rgb.b = hsv.v;
			break;
		case 4:
			rgb.r = t;
			rgb.g = p;
			rgb.b = hsv.v;
			break;
		default:
			rgb.r = hsv.v;
			rgb.g = p;
			rgb.b = q;
			break;
	}
	return rgb;
}

function setvalue(color) {
	parent.$(paramname + '_v').value = color + cvalueimg;
	var oldstyle = parent.$(paramname).style.background;
	var sp = oldstyle.indexOf(' ');
	var setstyle = '';
	if(sp == -1) {
		if(oldstyle.substr(0, 1) == '#') {
			setstyle = color;
		}
	} else {
		if(oldstyle.substr(0, 1) == '#') {
			setstyle = color + ' ' + oldstyle.substr(sp + 1);
		} else if(oldstyle.substr(sp + 1, 1) == '#') {
			setstyle = color + ' ' + oldstyle.substr(0, sp);
		}
	}
	setstyle = setstyle != '' ? setstyle : color;
	parent.$(paramname).style.background = setstyle;
}
</SCRIPT>
<STYLE>
BODY {
	padding:0px; margin:0px; background-color:#fff
}
TABLE {
	BORDER:#333 1px solid
}
</STYLE>
</HEAD>
<BODY onmousedown="getcolor(event);setvalue(hexstr);" scrolling="no">
<TABLE cellSpacing=0 cellPadding=0>
  <TBODY>
  <TR>
    <TD colSpan=2><IMG style="WIDTH: 164px; CURSOR: crosshair; HEIGHT: 164px" src="../images/color.jpg"></TD></TR>
</TBODY></TABLE>
<SCRIPT>
var obj = parent.$(paramname + '_v');
var sp = obj.value.indexOf(' ');
var cvalue = '';
var cvalueimg = '';

if(sp == -1) {
	if(obj.value.substr(0, 1) == '#') {
		cvalue = obj.value;
	}
} else {
	if(obj.value.substr(0, 1) == '#') {
		cvalue = obj.value.substr(0, sp);
		cvalueimg = ' ' + obj.value.substr(sp + 1);
	} else if(obj.value.substr(sp + 1, 1) == '#') {
		cvalue = obj.value.substr(sp + 1);
		cvalueimg = ' ' + obj.value.substr(0, sp);
	}
}
</SCRIPT>
</BODY></HTML>
